import * as constants from './constants'
import { message } from 'antd'
import { getUserInfo } from '../request/user'

export const setMenuCollapsed = () => ({ type: constants.MENU_COLLAPSED })
export const setLoginStatus = value => ({ type: constants.CHANGE_LOGIN_STATUS, value })
export const setBreadCrumb = value => ({ type: constants.SET_BREADCRUMB, value })

export const getLoginUser = () => {
  return async dispatch => {
    try {
      const { code, message: errMsg, data } = await getUserInfo()
      if (code) {
        message.error(errMsg)
        return false
      }
      dispatch({ type: constants.SET_LOGIN_USER, value: data })
    } catch (e) {
      message.error('获取用户信息失败')
    }
  }
}
